#include <iostream>
#include "sqldb.h"
#include "Controler.h"
#include "ClientSocket.h"


using namespace std;
myDatabase *pDB;
Controler *pControler;
ClientSocket *pClientSocket;


int main()
{
	try{
		//start the database
		myDatabase mydatabase;
		pDB=&mydatabase;

		int i=0;
		for(i=0;i<10;i++)
		{
			//可能mysql服务还没启动
			if(pDB->open(HOST,USER,PASSWORD,DBNAME))
				break;
			else
			{
				sleep(1);
				DBG("retry connect database\n");
			}
		}

		if(i==5)
		{
			 DBG("connect database failure!\n");
             return -1;
		}

#if 0
		//串口轮寻,main thread
		Controler controler;
		pControler=&controler;
		pControler->Start();
#endif



#if 1
	//客户端链接主机
	ClientSocket clientSocket("192.168.1.88",20131);
	pClientSocket=&clientSocket;
	pClientSocket->Start();
#endif


pause();

		//close
		pDB->close();
		delete pDB;


	}
	catch (Exception &e)
	{
		e.ShowReason();
	}


	return 0;

/*
	pClientSocket = new ClientSocket("220.181.111.147",80);
	//if(pClientSocket->ConnectToServer())
		cout<<pClientSocket->ConnectToServer()<<endl;
*/

}
